using CryptoFile.Library.LongArithmetic;

namespace CryptoFile.Library.Prime {
	public class MultiplicityChecker {
		private readonly BigNumber[] factors;

		public MultiplicityChecker() {
			factors = new[] {
			                	new BigNumber(new[] { 3 }),
			                	new BigNumber(new[] { 5 }),
			                	new BigNumber(new[] { 7 }),
			                	new BigNumber(new[] { 11 }),
			                	new BigNumber(new[] { 13 }),
			                	new BigNumber(new[] { 17 }),
			                	new BigNumber(new[] { 19 }),
			                	new BigNumber(new[] { 23 }),
			                	new BigNumber(new[] { 29 }),
			                	new BigNumber(new[] { 31 }),
			                	new BigNumber(new[] { 37 }),
			                	new BigNumber(new[] { 41 }),
			                	new BigNumber(new[] { 43 }),
			                	new BigNumber(new[] { 47 }),
			                	new BigNumber(new[] { 53 }),
			                	new BigNumber(new[] { 59 }),
			                	new BigNumber(new[] { 61 }),
			                	new BigNumber(new[] { 67 }),
			                	new BigNumber(new[] { 71 }),
			                	new BigNumber(new[] { 73 }),
			                	new BigNumber(new[] { 79 }),
			                	new BigNumber(new[] { 83 }),
			                	new BigNumber(new[] { 89 }),
			                	new BigNumber(new[] { 97 }),
			                	new BigNumber(new[] { 101 }),
			                	new BigNumber(new[] { 103 }),
			                	new BigNumber(new[] { 107 }),
			                	new BigNumber(new[] { 109 }),
			                	new BigNumber(new[] { 113 }),
			                	new BigNumber(new[] { 127 }),
			                	new BigNumber(new[] { 131 }),
			                	new BigNumber(new[] { 137 }),
			                	new BigNumber(new[] { 139 }),
			                	new BigNumber(new[] { 149 }),
			                	new BigNumber(new[] { 151 }),
			                	new BigNumber(new[] { 157 }),
			                	new BigNumber(new[] { 163 }),
			                	new BigNumber(new[] { 167 }),
			                	new BigNumber(new[] { 173 }),
			                	new BigNumber(new[] { 179 }),
			                	new BigNumber(new[] { 181 }),
			                	new BigNumber(new[] { 191 }),
			                	new BigNumber(new[] { 193 }),
			                	new BigNumber(new[] { 197 }),
			                	new BigNumber(new[] { 199 }),
			                	new BigNumber(new[] { 211 }),
			                	new BigNumber(new[] { 223 }),
			                	new BigNumber(new[] { 227 }),
			                	new BigNumber(new[] { 229 }),
			                	new BigNumber(new[] { 233 }),
			                	new BigNumber(new[] { 239 }),
			                	new BigNumber(new[] { 241 }),
			                	new BigNumber(new[] { 251 })
			                };
		}

		public bool Check(BigNumber number) {
			foreach (var factor in factors) {
				var compareResult = number.Compare(factor);
				if (compareResult == CompareResult.Less || compareResult == CompareResult.Equal)
					return false;
				if (number.Mod(factor).IsZero)
					return true;
			}
			return false;
		}
	}
}